<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 救生艇 -->
    <script>
      var numRescue = (people, limit) => {
        if (people.sort((a, b) => a - b)[0] >= limit) return people.length
        let res = 0
        for (let i = 0, j = people.length - 1; i <= j; people[i] + people[j] <= limit && i++, j--) {
          res++
        }
        return res
      }
      console.log(numRescue([1, 2], 3))
    </script>
  </body>
</html>
